<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.Set" %>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/Store/css/Administration.css" type="text/css">
<script src="jquery-2.1.1.min.js"> </script>
<script>

function addElement(className){
    
    var parentHTML = $("."+className).filter(":first").html();
    var child = document.createElement("tr");
    child.innerHTML = parentHTML;
    var removeButton = document.createElement("button");
    text = document.createTextNode("Премахни");
    removeButton.appendChild(text);
    $(removeButton).attr("type","button");
    $(removeButton).click(function(){
       $(this).parent().remove();
    
    });
    child.appendChild(removeButton);
    $(child).attr("class",className);
    $("."+className).filter(":last").after(child);
    
}
</script>
<title>Стъпка 2</title>
</head>
<body>
<% Map<Long, String> colors = (Map<Long, String> ) session.getAttribute("colors");
 Map<Long, String> sizes = (Map<Long, String> ) session.getAttribute("sizes");
Set<Long> colorIds = colors.keySet();
Set<Long> sizeIds = sizes.keySet();
%>
<div class="container"> 
<div class="main"> 
<form action="/Store/ChooseColorAndSize2" method="post">
<table> 

	<tr> 
		<td> Цвят: </td> 
		<td>
			<select name="colorId">
				
				<% for(long colorId: colorIds){%>
					<option value=<%=colorId %>> <%=colors.get(colorId)%></option>
				<%}%>
			</select>
		</td>
	</tr>
	<tr class="count">
		<td>Размер:</td>
		<td>
			<select name="sizeIds[]">
				
				<% for(long sizeId: sizeIds){%>
					<option value=<%=sizeId %>> <%=sizes.get(sizeId)%></option>
				<%}%>
			</select>
		</td>
		<td>Брой: </td>
		<td> <input type="number"  required min="1" name="counts[]"> </td>
		<td> <button type="button" onclick="addElement('count')"> Добави </button> </td>
	</tr>
	<tr>
		<td> <input type="submit" value="Продължи"></td>
		<td class="cancel"> <a href="/Store/Supplier.html"> <button type="button"> Отмени </button> </a></td>
	</tr>

</table>
</form>	
</div>
</div>
</body>
</html>